package com.zbf.config.client.taskforAutoRefresh;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

/**
 * 作者：LCG
 * 创建时间：2019/3/26 17:02
 * 描述：
 */

@Component
public class TaskForRefresh {
    @Autowired
    private WebApplicationContext webApplicationContext;

    @Scheduled(cron = "0/5 * * * * ?")
    public void toRefreshConfig() throws Exception {
        System.out.println ("========定时任务========");
        MockMvc mockMvc = MockMvcBuilders.webAppContextSetup ( webApplicationContext ).build ();
        mockMvc.perform ( MockMvcRequestBuilders.
                post ( "http://localhost:9998/refresh" )
                .accept ( MediaType.ALL )
        ).andExpect ( MockMvcResultMatchers.status ().isOk () );
    }

}
